using System; using System.Linq.Expressions; using UnityEngine.UIElements; #if UNITY_EDITOR using UnityEditor; using UnityEditor.UIElements; #endif namespace AV.UITK { public partial class FluentElement { // TODO: Challenge! Try to achieve complex binding with InspectorPrefs.PatchesTable // TODO: SerializedProperty wrapper with linq-like deep iteration, i.e. Where("key", x => x.stringValue == patch.prefKey) public FluentElement Bind(string bindingPath) { if (x is BindableElement bindable) bindable.bindingPath = bindingPath; else throw new Exception($"{x.name} is not a BindableElement. Can't assign '{bindingPath}' as binding path."); return x; } /// Retrieves full path of a source member and sets it as a binding path. public FluentElement Bind(Expression> member) { var fullPath = FluentUITK.GetMemberPath(member); Bind(fullPath); return x; } #if UNITY_EDITOR public FluentElement Bind(SerializedProperty property) { Bind(property.propertyPath); return x; } public FluentElement Bind(SerializedObject serializedObject) { x.Bind(serializedObject); return x; } #else public FluentElement Bind(object nothing) => x; #endif #if UNITY_EDITOR public void Unbind() => x.Unbind(); #endif #if UNITY_EDITOR public FluentElement NewField(SerializedProperty property, string label = null) { return new PropertyField(property) { label = label }; } #else public FluentElement NewField(object property, string label = null) => x; #endif #if UNITY_EDITOR public FluentElement NewField(string bindingPath, string label = null) { return new PropertyField { bindingPath = bindingPath, label = label }; } #else public FluentElement NewField(string bindingPath, string label = null) => x; #endif #if UNITY_EDITOR public FluentElement NewField(Expression> member, string label = null) { var bindingPath = FluentUITK.GetMemberPath(member); return new PropertyField { bindingPath = bindingPath, label = label }; } #else public FluentElement NewField(Expression> member, string label = null) => x; #endif } }